package logic;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Vector;

public class FileRepository  implements Serializable{

	/** 
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Vector<myFile> files;
	public FileRepository()
	{
		files=new Vector<myFile>();
	}
	public void addFile(myFile f)
	{
		files.add(f);
	}
	public Vector<myFile> getFiles() {
		return files;
	}

	public void setFiles(Vector<myFile> files) {
		this.files = files;
	}
	public void saveInFile(String name) throws IOException
	{
		FileOutputStream fout = new FileOutputStream(name);
		@SuppressWarnings("resource")
		ObjectOutputStream oos = new ObjectOutputStream(fout);
		oos.writeObject(this);
	}
	public Vector<String> getFileNames() {
		Vector<String> vec = new Vector<String>();
		for(int i = 0; i<files.size();i++)
		{
			vec.add(files.elementAt(i).extractNameFile());
		}
		return vec;
		
	}
	public myFile getFile(String filename)
	{
		for(int i = 0; i<files.size();i++)
		{
			if(files.elementAt(i).getName() == filename)
				return files.elementAt(i);
		}
		return null;
	}
	
	
}
